package org.example.util;

/**
 * @Description
 * @Author chenhs
 * @Date 22:01 2025/7/27
 */
import java.io.*;
import java.net.*;

public class TcpClient {
    public static void main(String[] args) {
        String host = "192.168.1.8";
        int port = 6800;
        String message = "测试数据";

        try (Socket socket = new Socket();
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true)) {

            socket.connect(new InetSocketAddress(host, port), 5000); // 5秒超时
            out.println(message);
            System.out.println("数据发送成功: " + message);

        } catch (SocketTimeoutException e) {
            System.err.println("连接超时");
        } catch (IOException e) {
            System.err.println("发送失败: " + e.getMessage());
        }
    }
}